﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
using ZH.Infrastructure.Dto.Request.Login;
using ZH.Infrastructure.Dto.Response.admin;
using ZH.Infrastructure.Dto.Response;
using ZH.Infrastructure.Tools;
using ZH.Service.Interface;
using ZH.Service.Instance;
using ZH.Infrastructure.Dto.Request.Tech;
using ZH.Infrastructure.Dto.Request.Yuyue;
using ZH.Infrastructure.EFCore.MySql;
using Mysqlx.Crud;
using ZH.Infrastructure.Dto.Response.Article;

namespace ZH.Api.Admin.Controllers.Mobile
{
    /// <summary>
    /// 移动端文章
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ArticleController : Controller
    {
        public readonly I_Mobile_Service _mobile_Service;
        private readonly I_Article_Service _i_article_service;


        public ArticleController(I_Mobile_Service mobile_Service, I_Article_Service _article_service)
        {

            _mobile_Service = mobile_Service;
            _i_article_service = _article_service;
        }


        /// <summary>
        /// 
        /// 获取文章
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_article(int? page=1, int? limit=10, string? key="")
        {
            var result = await _i_article_service.Get_article(page,limit,key);
            return Ok(result);
        }

        /// <summary>
        /// 添加文章
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_art(Article_Response_Dto dto) {


            var result = await _i_article_service.Add_art(dto);
            return Ok(result);
        }


        /// <summary>
        /// 修改文章
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> update_art(Article_Response_Dto dto)
        {


            var result = await _i_article_service.update_art(dto);
            return Ok(result);
        }

        /// <summary>
        /// 删除文章
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> delete_art(string id)
        {


            var result = await _i_article_service.delete_art(id);
            return Ok(result);
        }



    }
}
